// DoublePointer.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

/*
* 双指针通常用于遍历数组，两个指针指向不同的元素，从而协同完成任务。也可以延伸到多个数组的多个指针。
* 若两个指针指向同一数组，遍历方向相同且不会相交，则也称为滑动窗口（两个指针包围的区域即为当前的窗口），经常用于区间搜索。
* 若两个指针指向同一数组，但是遍历方向相反，则可以用来进行搜索，待搜索的数组往往是排好序的。
*/

#include <iostream>
#include"TwoSum.h"
#include"CircularList.h"

void TwoSumSolution() {
    cout << "两数之和: " << endl;
    vector<int> numbers;
    int number;

    cout << "请输入数组, 回车后 ctrl+z 退出输入" << endl;
    while (cin >> number) {
        numbers.push_back(number);
    }

    cin.clear();
    cin.sync();

    cout << "请输入目标值, 回车后结束" << endl;
    int target;
    cin >> target;

    TwoSum(numbers, target);
}

void CircularListSolution() {
    ListNode* node1 = new ListNode();
    ListNode* node2 = new ListNode();
    ListNode* node3 = new ListNode();
    ListNode* node4 = new ListNode();
    ListNode* node5 = new ListNode();
    ListNode* node6 = new ListNode();
    ListNode* node7 = new ListNode();

    node1->next = node2;
    node2->next = node3;
    node3->next = node4;
    node4->next = node5;
    node5->next = node6;
    node6->next = node7;
    node7->next = nullptr;

    if (CircularList(node1))
        cout << "环形链表" << endl;

    else
        cout << "非环形链表" << endl;
 
}

int main()
{
    CircularListSolution();
}
